<?php
	require_once('../utils/query.php');
	require_once('../utils/logged_in.php');
	$tradeID = $_POST["tradeID"];
	
?>

<!--<ul class="cards">-->
<ul>
	<?php


		if($tradeID) // if a tradeID was passed - should be from the file tradeHome.php passed in the function loadCards(paramater)
		{		
			$tradeCards = execute_query("SELECT possessionid FROM TradePossession WHERE tradeid='%s'", $tradeID);
		}
		else // a tradeID was not passed in, so return the possessionids based on the $drupalid
		{
			$tradeCards = execute_query("SELECT possessionid FROM Possession WHERE userid='%s' ORDER BY cardid", $drupaluid);
		}
		


		while ($row = mysql_fetch_array($tradeCards)) {  // will return an array of all the possesion ids based on either the $tradeID or $drupaluid
			$cardID = execute_query("SELECT cardid FROM Possession WHERE possessionid='%s'", $row[0]); // select the cardid based on the possessionid 
			$cardID = mysql_result($cardID,0); // (data, row#) The data pointer is the return from the mysql_query() function. row = which row# to get starting at zero
			// I believe cardid in possession and full_id in card_lu are the same.
			$cards_result = execute_query("SELECT name, card_img, type FROM cards_lu WHERE front is null AND full_id='%s'", $cardID);
			$row2 = mysql_fetch_array($cards_result);
			$name = $row2[0];
			$card_img = $row2[1];
			$type = $row2[2];
			
			$color = "#ffffff";

			if ($type == 1)
				$color = "#dc3122";
			else if ($type == 2)
				$color = "#ddd327";
			else if ($type == 3)
				$color = "#0145f3";
			else if ($type == 10)
				$color = "#653b67";
				
		
			if(strlen($name) > 16)
			$showname = substr ($name,0,16) . "...";
			else
			$showname = $name;
	?>
			
			<li class="card" id="<?php echo($cardID); ?>">
				<div class="cardImg">
					<img src="../../../card_imgs/<?php echo($card_img); ?>">
				</div>
				<!--<div class="cardDesc" style="background:<?php echo($color); ?>;">-->
				<div class="cardDesc">
					<?php echo($showname); ?>
				</div>
			</li>
	<?php
		}
		
	?>
</ul>